﻿using System;
using System.Xml.Serialization;

namespace SimpleMediaManager.TMDB
{
    [XmlType("also_known_as")]
    public class AlsoKnownAs
    {
        [XmlElementAttribute("name")]
        public string[] Names { get; set; }
    }

    [XmlType("movie")]
    public class PersonFilm
    {
        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlAttribute("job")]
        public string Job { get; set; }

        [XmlAttribute("department")]
        public string Department { get; set; }

        [XmlAttribute("url")]
        public string Url { get; set; }

        [XmlAttribute("character")]
        public string Character { get; set; }

        [XmlAttribute("id")]
        public int Id { get; set; }
    }

    [XmlType("person")]
    public class Person
    {
        [XmlElement("score")]
        public decimal Score { get; set; }

        [XmlElement("popularity")]
        public decimal Popularity { get; set; }

        [XmlElement("name")]
        public string Name { get; set; }

        [XmlElementAttribute("also_known_as")]
        public AlsoKnownAs AlsoKnownAs { get; set; }

        [XmlElement("url")]
        public string Url { get; set; }

        [XmlElement("id")]
        public int Id { get; set; }

        [XmlElement("biography")]
        public string Biography { get; set; }

        [XmlElement("known_movies")]
        public int KnownMovies { get; set; }

        [XmlElement("birthday")]
        public string BirthdayString { get; set; }

        public DateTime? Birthday
        {
            get
            {
                DateTime d;
                if (string.IsNullOrEmpty(BirthdayString) || !DateTime.TryParse(BirthdayString, out d))
                    return null;
                else
                    return d;
            }
        }

        [XmlElement("birthplace")]
        public string Birthplace { get; set; }

        [XmlArrayAttribute("images")]
        public Image[] Images { get; set; }

        [XmlArrayAttribute("filmography")]
        public PersonFilm[] Filmography { get; set; }
    }
}
